package com.example.micro.consumer.controller;

import com.example.micro.consumer.vo.UserVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

@RestController
@RequestMapping("/c/user")
public class UserController {

    @Autowired
    @Qualifier("restTemplate")
    private RestTemplate restTemplate;

    /**
     * 根据id获取用户信息
     *
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    public UserVo queryUserById(@PathVariable("id") Integer id) {
        String url = String.format("http://%s/p/user/%s", "micro-provider", id);
        return restTemplate.getForObject(url, UserVo.class);
    }


}
